package xyz.jangle.design.prototype;

public class AppMain16 {

	public static void main(String[] args) {
		
		try {
			// 基本数据类型克隆
			ConcretePrototype1 prototype1 = new ConcretePrototype1(1, 2, 3);
			ConcretePrototype1 self = (ConcretePrototype1) prototype1.cloneSelf();
			System.out.println("a:"+self.a+",b:"+self.b+",c:"+self.c);
			
			// 字符串克隆
			ConcretePrototype2 prototype2 = new ConcretePrototype2("123");
			ConcretePrototype2 self2  = (ConcretePrototype2) prototype2.cloneSelf();
			System.out.println(self2.getStr());
			self2.setStr("456");
			System.out.println(prototype2.getStr());
			
			// 对象克隆
			ConcretePrototype3 prototype3 = new ConcretePrototype3();
			AAA aaa = new AAA();
			aaa.setA(1);
			aaa.setB(2);
			prototype3.setAaa(aaa);
			ConcretePrototype3 self3 = (ConcretePrototype3) prototype3.cloneSelf();
			AAA aaa2 = self3.getAaa();
			System.out.println(aaa2.getA()+","+aaa2.getB());
			System.out.println(aaa==aaa2);	//false   克隆出的2个引用不一样
			aaa2.setA(7);
			aaa2.setB(8);
			System.out.println(aaa.getA()+","+aaa.getB());	// 1,2
			
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}

	}

}
